function Registered = TTRegister(TTImage,FixedImage,MaxTranslationStep)
%CPU: CPU+5
%GPU: CPU+0, GPU+5
[SizeX,SizeY,SizeT,SizeZ,SizeC]=size(TTImage);
if isgpuarray(TTImage)
	XCorrs=zeros(SizeX*2-1,SizeY*2-1,SizeT,SizeZ,SizeC,'single','gpuArray');
else
	XCorrs=zeros(SizeX*2-1,SizeY*2-1,SizeT,SizeZ,SizeC,'single');
end
for C=1:SizeC
	for Z=1:SizeZ
		for T=1:SizeT
			Sample=TTImage(:,:,T,Z,C);
			%Sample(Sample<mean2(Sample))=0;
			if std2(Sample)==0
				XCorrs(SizeX,SizeY,T,Z,C)=1;
			else
				XCorrs(:,:,T,Z,C)=normxcorr2(Sample,FixedImage(:,:,:,Z,C));
			end
		end
	end
end
[~,Xs,Ys]=MATLAB.DataFun.MaxSubs(XCorrs(SizeX-MaxTranslationStep:SizeX+MaxTranslationStep,SizeY-MaxTranslationStep:SizeY+MaxTranslationStep,:),[1 2]);
Xs=Xs-MaxTranslationStep-1;
Ys=Ys-MaxTranslationStep-1;
RXS=max(1,Xs+1);
RXE=min(SizeX,SizeX+Xs);
RYS=max(1,1+Ys);
RYE=min(SizeY,SizeY+Ys);
MXS=max(1,1-Xs);
MXE=min(SizeX,SizeX-Xs);
MYS=max(1,1-Ys);
MYE=min(SizeY,SizeY-Ys);
Registered=zeros(SizeX,SizeY,SizeT,SizeZ,SizeC,'like',gather(TTImage(1)));
for I=1:SizeT*SizeZ*SizeC
	Registered(RXS(I):RXE(I),RYS(I):RYE(I),I)=TTImage(MXS(I):MXE(I),MYS(I):MYE(I),I);
end